package com.hotelvip.controller;

import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.service.UserService;
import com.hotelvip.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Lzh
 * @date 2020/12/14 14:34
 */
@RestController
@RequestMapping("/user")
@Api(basePath = "/user",tags = "客户用户模块")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 添加新客户用户
     * @param user
     * @return
     */
    @ApiOperation(value = "添加新客户用户",httpMethod = "POST")
    @PostMapping("/saveUser")
    public JSONResult saveUser(@RequestBody UserVo user){
        userService.saveUser(user);
        return JSONResult.ok("添加成功");
    }

    /**
     * 根据id查找客户用户信息
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查找客户用户",httpMethod = "GET")
    @GetMapping("/findUserById/{id}")
    public JSONResult findUserById(@PathVariable Long id){
        return JSONResult.ok(userService.findUserById(id));
    }

    /**
     * 查找所有客户用户
     * 每页显示20条
     * @return
     */
    @ApiOperation(value = "查找所有客户用户",httpMethod = "GET")
    @GetMapping("/findUser")
    public JSONResult findUser(
            @ApiParam(value = "当前页码",required = true) @RequestParam(value = "current") Long current,
            @ApiParam(value = "每页条数",required = true) @RequestParam(value ="size") Long size) {
        return JSONResult.ok(userService.findUsers(current,size));
    }

    /**
     * 按照id修改该用户信息
     * @param userVo
     * @return
     */
    @ApiOperation(value = "按照id修改该用户信息",httpMethod = "PUT")
    @PutMapping("/updateUserInfo")
    public JSONResult updateUserInfo(@RequestBody UserVo userVo){
        userService.updateUserInfo(userVo);
        return JSONResult.ok("修改客户信息成功");
    }

    @ApiOperation(value = "按照id删除客户用户信息",httpMethod = "DELETE")
    @DeleteMapping("/deleteUserByIds")
    public JSONResult deleteUserByIds(@RequestParam("ids") List<Long> ids){
        userService.deleteUserByIds(ids);
        return JSONResult.ok("删除成功");
    }
    @ApiOperation(value = "查询所有已删除的用户",httpMethod = "GET")
    @GetMapping("/getDeleteUsers")
    public JSONResult getDeleteUsers(){
        return JSONResult.ok(userService.getDeleteUsers());
    }
}
